package com.zat.mes.andrmes.dofun.work.adapter

import android.text.TextUtils
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.WorkWageBean
import com.zat.mes.andrmes.utils.SpannableStrUtil

/**
 * @author zy
 * @date :2020-02-22 09:28
 * @description: 领取裁片包
 */
class WorkWageAdapter(layoutResId: Int) :
    BaseQuickAdapter<WorkWageBean, BaseViewHolder>(layoutResId), LoadMoreModule {

    override fun convert(helper: BaseViewHolder, item: WorkWageBean) {
        helper.setText(R.id.tvProduceWageItem, item?.productName)
        helper.setText(
            R.id.tvallWageItem,
            context.getString(R.string.text_salary) + "：￥" + String.format("%.2f", item?.sumAmount)
        )
        helper.setText(R.id.tvDateWageItem, item?.workDate)
        val textColor = ContextCompat.getColor(context, R.color.color_text_grey2)
        var styleNo = context.getString(R.string.text_style) + "：" + item?.styleNo
        var procName = context.getString(R.string.text_proc) + "：" + item?.procName
        var sumPiece = context.getString(R.string.text_sumpiece) + "：" + item?.sumPiece
        var sumPack = context.getString(R.string.text_pack_amount) + "：" + item?.sumPack
        var wage =
            context.getString(R.string.text_wage) + "：￥" + String.format("%.2f", item?.selfWage)
        if (TextUtils.isEmpty(item?.styleNo)) {
            styleNo = context.getString(R.string.text_style) + "："
            helper.setText(R.id.tvStyleNoWageItem, styleNo)
        } else {
            helper.setText(
                R.id.tvStyleNoWageItem,
                SpannableStrUtil.getColorSpannable(styleNo, 3, styleNo.length, textColor)
            )
        }
        if (TextUtils.isEmpty(item?.procName)) {
            procName = context.getString(R.string.text_proc) + "："
            helper.setText(R.id.tvProcNameWageItem, procName)
        } else {
            helper.setText(
                R.id.tvProcNameWageItem,
                SpannableStrUtil.getColorSpannable(procName, 3, procName.length, textColor)
            )
        }
        if (TextUtils.isEmpty(item?.sumPiece)) {
            sumPiece = context.getString(R.string.text_sumpiece) + "："
            helper.setText(R.id.tvQtyWageItem, sumPiece)
        } else {
            helper.setText(
                R.id.tvQtyWageItem,
                SpannableStrUtil.getColorSpannable(sumPiece, 4, sumPiece.length, textColor)
            )
        }
        if (TextUtils.isEmpty(item?.sumPack)) {
            sumPack = context.getString(R.string.text_pack_amount) + "："
            helper.setText(R.id.tvPacksWageItem, sumPack)
        } else {
            helper.setText(
                R.id.tvPacksWageItem,
                SpannableStrUtil.getColorSpannable(sumPack, 3, sumPack.length, textColor)
            )
        }
        helper.setText(
            R.id.tvSelfWageItem,
            SpannableStrUtil.getColorSpannable(wage, 3, wage.length, textColor)
        )

    }
}